//
//  CampusQuetionItemCell.m
//  ShowYork
//
//  Created by hxh on 2021/3/26.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "CampusQuetionItemCell.h"

@interface CampusQuetionItemCell ()
@property (nonatomic,strong)UILabel *titleLb;
@property (nonatomic,strong)UILabel *dateLb;
@property (nonatomic,strong)UILabel *answerLb;
@property (nonatomic,strong)UIView *line;
@property (nonatomic,strong)UIButton *coverBtn;
@end

@implementation CampusQuetionItemCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    self.titleLb = [[UILabel alloc]init];
    self.titleLb.textColor = C51;
    self.titleLb.font = [UIFont boldSystemFontOfSize:14];
    self.titleLb.numberOfLines = 2;
    [self.contentView addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20);
        make.top.equalTo(self.contentView).offset(16);
        make.right.equalTo(self.contentView).offset(-20);
    }];
    
    self.dateLb = [[UILabel alloc]init];
    self.dateLb.textColor = RGBA(163, 163, 163, 1);
    self.dateLb.font = font(10);
    [self.contentView addSubview:self.dateLb];
    [self.dateLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-18);
        make.top.equalTo(self.titleLb.mas_bottom).offset(16);
        make.bottom.equalTo(self.contentView).offset(-16);
    }];
    
    self.answerLb = [[UILabel alloc]init];
    self.answerLb.textColor = RGBA(163, 163, 163, 1);
    self.answerLb.font = font(10);
    [self.contentView addSubview:self.answerLb];
    [self.answerLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20);
        make.centerY.equalTo(self.dateLb);
    }];
    
    self.line = [[UIView alloc]init];
    self.line.backgroundColor = RGBA(230, 230, 230, 1);
    [self.contentView addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(20);
        make.right.equalTo(self.contentView).offset(-20);
        make.bottom.equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
    self.coverBtn = [[UIButton alloc]init];
    [self.coverBtn addTarget:self action:@selector(coverMethod) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:self.coverBtn];
    [self.coverBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.equalTo(self.contentView);
    }];
}
+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"CampusQuetionItemCell";
    CampusQuetionItemCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[CampusQuetionItemCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}
- (void)setItemModel:(CampusSchoolQuestionItemModel *)itemModel{
    _itemModel = itemModel;
    self.titleLb.text = itemModel.question;
    self.dateLb.text = itemModel.createDetailTimeStr;
   
    NSString *title = @"";
    NSInteger count = itemModel.answerCount.intValue;
    if (itemModel.answerCount.intValue >= 10000) {
        if (count % 1000 == 0) {
            count += 1;
        }
        title = [NSString stringWithFormat:@"%@w个回答",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        if (count == 0) {
            title = @"";
        }else{
            title = [NSString stringWithFormat:@"%lu个回答",count];
        }
    }
    self.answerLb.text = title;
}
- (void)coverMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showQuestionDetail:)]) {
        [self.delegate showQuestionDetail:self.itemModel];
    }
}

@end
